﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

using ent;

public partial class shared_recent : System.Web.UI.UserControl {
    public String URL = ApplicationCommon.getPath();

    public String LIST_ID = String.Empty;
    public String TITLE = String.Empty;
    public String LINK_URL = String.Empty;
    public String LINK_TITLE = String.Empty;
    public String TBL__name = String.Empty;
    public String TBL__id = String.Empty;

    public String UPLOAD_SESSION_ID = String.Empty;
    public String UPLOAD_USER_ID = "0";
    public String UPLOAD_MODE = String.Empty;
    public String UPLOAD_ID = "0";

    private bool _permitManagement = false;

    private TableUsers t1 = new TableUsers();

#region Properties

    public String prop_LIST_ID {
        get {return LIST_ID;}
        set {LIST_ID = value;}
    }
    public String prop_TITLE {
        get {return TITLE;}
        set {TITLE = value;}
    }
    public String prop_LINK_URL {
        get {return LINK_URL;}
        set {LINK_URL = value;}
    }
    public String prop_LINK_TITLE {
        get {return LINK_TITLE;}
        set {LINK_TITLE = value;}
    }
    public String prop_TBL__id {
        get {return TBL__id;}
        set {TBL__id = value;}
    }
    public String prop_TBL__name {
        get {return TBL__name;}
        set {TBL__name = value;}
    }
    public bool prop_permitManagement {
        get {return _permitManagement;}
        set {_permitManagement = value;}
    }
    public PlaceHolder prop_plhJavaScriptUpload {
        get {return plhJavaScriptUpload;}
        set {plhJavaScriptUpload = value;}
    }
    public Repeater prop_rptrRecentItems {
        get {return rptrRecentItems;}
        set {rptrRecentItems = value;}
    }

#endregion

    protected void Page_Init(Object sender, EventArgs e) {}
    protected void Page_Load(Object sender, EventArgs e) {
        if(plhJavaScriptUpload.Visible && ApplicationCommon.isValidSession(Session)) {
            UPLOAD_SESSION_ID = Session.SessionID;
            UPLOAD_USER_ID = Session[ApplicationCommon.SESSION__user_id].ToString();
            UPLOAD_MODE = "add";
        }
    }

#region Events

    protected void rptrRecentItems_ItemCreated(Object sender, RepeaterItemEventArgs e) {
        if(e.Item.ItemType == ListItemType.Header) {
            System.Text.StringBuilder sbHeader = new System.Text.StringBuilder();
            Literal litMarkupHeader = (Literal)e.Item.FindControl("litHeader");

            sbHeader.AppendFormat("<ul id=\"{0}\"><li class=\"header\">{1}</li>", prop_LIST_ID, TITLE);
            litMarkupHeader.Text = sbHeader.ToString();
        }
        if(e.Item.ItemType == ListItemType.Footer) {
            System.Text.StringBuilder sbFooter = new System.Text.StringBuilder();
            Literal litMarkupFooter = (Literal)e.Item.FindControl("litFooter");

            sbFooter.AppendFormat("</ul>");
            litMarkupFooter.Text = sbFooter.ToString();
        }
    }
    protected void rptrRecentItems_ItemDataBound(Object sender, RepeaterItemEventArgs e) {
        // This event is raised for the header, the footer, separators, and items.
        if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
            System.Data.DataRowView drv1 = (System.Data.DataRowView)e.Item.DataItem;

            // Get controls.
            Literal litMarkup = (Literal)e.Item.FindControl("litItemMarkup");

            // Create markup for link.
            System.Text.StringBuilder sb1 = new System.Text.StringBuilder();
            System.Collections.Hashtable qs1 = new System.Collections.Hashtable();
            qs1.Add("id", drv1[TBL__id].ToString());
            String linkUrl = ResolveClientUrl(ApplicationCommon.setQueryString(qs1, LINK_URL));
            String linkInner = (String)drv1[TBL__name];
            sb1.AppendFormat("<a href=\"{0}\" title=\"{1}\">{2}</a>", linkUrl, LINK_TITLE, linkInner);

            // Create markup code for list item.
            System.Text.StringBuilder sb2 = new System.Text.StringBuilder();
            sb2.AppendFormat("<li>{0}</li>", sb1);
            litMarkup.Text = sb2.ToString();
        }
    }
    protected void rptrRecentItems_ItemCommand(Object sender, RepeaterCommandEventArgs e) { }

#endregion

}